package com.wimcorp.magic.abilities;

import java.rmi.RemoteException;

import javax.persistence.Entity;
import javax.persistence.Table;

import com.wimcorp.magic.abilities.trigger.AbilityTrigger;
import com.wimcorp.magic.cards.PlayingCard;
import com.wimcorp.magic.exception.CastException;

@Entity
@Table(name = "futuresight", schema = "abilities")
public class FutureSight extends Ability {

	protected FutureSight() {
	}

	public FutureSight(AbilityTrigger trigger) {
		super(trigger);
	}

	public FutureSight(FutureSight ability) {
		super(ability);
	}
	
	public void cast() throws Exception {
		PlayingCard card = getPlayer().getDeck().reveal();
		String message = card.toString();
		getPlayer().getUserInterface().message(String.format("Future sight : %s. ", message));
		getPlayer().getOpponent().getUserInterface().message(String.format("Opponents' reveals top card of deck : %s. ",message));
		boolean playCard = getPlayer().getUserInterface().selectBoolean(String.format("Would you like to play %s? ",card.getName()));
		if (playCard) {
			getPlayer().castFromDeck();
			cast();
		}
	}


	@Override
	protected void executeAbility() throws CastException {

	}

	public void uncast() {
		getPlayer().getDeck().unRegisterDrawObserver(getPlayer(), this);
	}

	@Override
	public FutureSight clone() {
		return new FutureSight(this);
	}
	
}
